﻿namespace SvGame.Logic;

public static partial class GameLogic
{
    //技能升级所需潜能
    public static long GetPotLevelup(int skilllv)
    {
        long lv = skilllv + 1;
        return (lv * lv);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="me"></param>
    /// <param name="skillId"></param>
    /// <param name="quotiety">有效等级 true=有效等级 false=正常等级</param>
    /// <returns></returns>
    public static int SkillGetLevel(this IRole me, string skillId, bool quotiety = false)
    {
        me.Skills.TryGetValue(skillId, out var skill);
        if (quotiety)
        {
            if (ConfSkill.TryGetValue(skillId, out var conf))
            {
                skill = skill * conf.Quotiety / 100;
            }
        }
        return skill;
    }
    /// <summary>
    /// 获取激发等级
    /// </summary>
    /// <param name="me"></param>
    /// <param name="usage"></param>
    /// <returns></returns>
    public static int UsageGetLevel(this IRole me, EUsageType usage)
    {
        var usageLevel = 0;
        usageLevel += me.SkillGetLevel(usage.ToString(), true);
        if (me.Usages.TryGetValue(usage.ToString(), out var skillId))
        {
            usageLevel += me.SkillGetLevel(skillId, true);
        }
        return usageLevel;
    }
    /// <summary>
    /// 获取激发技能和激发等级
    /// </summary>
    /// <param name="me"></param>
    /// <param name="usage"></param>
    /// <param name="skillId"></param>
    /// <param name="usageLevel"></param>
    /// <returns></returns>
    public static bool UsageGet(this IRole me, EUsageType usage, out string skillId, out int usageLevel)
    {
        usageLevel = 0;
        usageLevel += me.SkillGetLevel(usage.ToString(), true);
        if (me.Usages.TryGetValue(usage.ToString(), out skillId))
        {
            usageLevel += me.SkillGetLevel(skillId, true);
        }
        else
        {
            skillId = "";
        }
        return !(skillId.IsNullOrEmpty() || skillId == "无");
    }
    /// <summary>
    /// 获取激发技能和激发等级
    /// </summary>
    /// <param name="me"></param>
    /// <param name="usageName"></param>
    /// <param name="skillId"></param>
    /// <param name="usageLevel"></param>
    /// <returns></returns>
    public static bool UsageGet(this IRole me, string usageName, out string skillId, out int usageLevel)
    {
        if (!usageName.TryParseEnum<EUsageType>(out var usage))
        {
            skillId = "";
            usageLevel = 0;
            return false;
        }
        return me.UsageGet(usage, out skillId, out usageLevel);
    }
    public static Dictionary<EUsageType, InfoUsage> UsageGetAll(this Player player)
    {
        var dict = new Dictionary<EUsageType, InfoUsage>();
        foreach (EUsageType item in Enum.GetValues(typeof(EUsageType)))
        {
            if (player.SkillGetLevel(item.ToString()) <= 0)
            {
                continue;
            }
            player.UsageGet(item, out var SkillId, out var level);
            var node = new InfoUsage()
            {
                Usage = item.ToString(),
                Skill = SkillId,
                UsageLevel = level,
            };
            dict[item] = node;
        }
        return dict;
    }
}
